﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using tracker.Models;
using tracker.Models.DTO;
using tracker.Models.DAL;
using tracker.Models.BLL;

namespace tracker.Controllers
{
    public class HandlerUpdateGroupInfoController : Controller
    {
        //
        // GET: /HandlerUpdateGroupInfo/

        public string Index(string GroupID, 
                                    string Name,
                                    string Address,
                                    string CellPhone,
                                    string Email,
                                    string userexpiredtime,
                                    string TelePhone,
                                    string usertrackerlimit,
                                    string AccountStatus,
                                    string Usernote)
        {
            string result = "";
            if (Utilities.isDateTime(userexpiredtime) && Utilities.isInt(usertrackerlimit))
            {
                EUserLoginBLL userDAL = new EUserLoginBLL();

                EUserLogin ent = userDAL.getBySecurityCode(GroupID);
                if (ent != null)
                {
                    ent.Address = Address;
                    ent.Email = Email;

                    ent.ModifyDate = DateTime.Now;

                    ent.NumberOfDevice = int.Parse(usertrackerlimit);
                    ent.Phone = CellPhone;

                    if (Utilities.isInt(AccountStatus))
                    {
                        ent.Status = int.Parse(AccountStatus);
                    }
                    else
                    {
                        //translateStatus(context, ent, accountstatus);
                    }

                    ent.Cellphone = CellPhone;
                    ent.Fullname = Name;

                    if (ent.UserGroupID == 3)
                    {
                        ent.Note = Usernote;
                        ent.EndDate = DateTime.Parse(userexpiredtime);
                    }

                    if (ent.UserGroupID == 3 || ent.UserGroupID == 4)
                    {
                        result = new UserLoginDAL().UpdateGroup(ent);
                    }

                }
            }
            return result=="0"?"true":"false";
        }

    }
}
